package com.itheima.interface3;

public class ClassDatainterImpl2 implements ClassDataInter {
    private Student[] students;     //记住送进来的全班学生对象信息

    //有参构造器
    public ClassDatainterImpl2(Student[] students) {
        this.students = students;
    }

    @Override
    public void printAllStudentInfos() {
        int maleCount=0;
        for (int i = 0; i < students.length; i++) {
            Student s=students[i];
            System.out.println(s.getName() + " " + s.getSex() + " " + s.getScore());
            if(s.getSex()=='男'){
                maleCount++;
            }
        }
        System.out.println("全班男生数量是:" + maleCount);
        System.out.println("全班女生数量是:" + (students.length-maleCount));
    }

    @Override
    public void printAverageScore() {
        System.out.println("平均分如下:");
        Student s1=students[0];
        double sum=0;
        double max=s1.getScore();
        double min=s1.getScore();
        for (int i = 0; i < students.length; i++) {
            Student s=students[i];
            sum+=s.getScore();

            if(s.getScore()>max){
                max=s.getScore();
            }

            if(s.getScore()<min){
                min=s.getScore();
            }
        }
        System.out.println("最高分"+max);
        System.out.println("最低分"+min);
        System.out.println("平均分是:" + (sum-max-min)/(students.length-2));

    }
}
